<?php
abstract class abstract_product_model extends Model{

    protected $language_id;
    protected $user_group_id;

    protected $plugins;
    protected $plugins_path;

    public function __construct ($registry){
        parent::__construct($registry);

        if ($registry->get('auth')->is_logged()) {
            $this->user_group_id = $registry->get('customer')->get_group_id();
        } else {
            $this->user_group_id = $registry->get('setting')->get('config_user_group_id');
        }	

        $this->language_id = $registry->get('setting')->get('setting_language_id');

        $this->plugins = array();
        $this->plugins_path = $this->load->get_path('dir_library') . 'product/plugin/';
    }

    public function getPlugin($plugin){

        if(!isset($this->plugins[$plugin])){
            if(!file_exists($this->plugins_path . $plugin. '.php')){
                throw new Exception('Module Product: cant load plugin "'. $this->plugins_path . $plugin. '.php" ');
            }

            include_once($this->plugins_path . $plugin. '.php');

            $class = "product_plugin_" . $plugin;

            $this->plugins[$plugin] = new $class(
                $this->registry,
                $this->user_group_id, 
                $this->language_id
            );
        }

        return $this->plugins[$plugin]; 
    }
}
